<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<!-- 网页使用的语言 -->
<html lang="zh-CN">
<head>
    <!-- 指定字符集 -->
    <meta charset="utf-8">
    <!-- 使用Edge最新的浏览器的渲染方式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- viewport视口：网页可以根据设置的宽度自动进行适配，在浏览器的内部虚拟一个容器，容器的宽度与设备的宽度相同。
    width: 默认宽度与设备的宽度相同
    initial-scale: 初始的缩放比，为1:1 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>菜品信息</title>

    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="js/bootstrap.min.js"></script>
    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>

    <script>
        function deleteUser(id){
            //用户安全提示
            if(confirm("您确定要删除吗？")){
                //访问路径
                location.href="${pageContext.request.contextPath}/delUserServlet?id="+id;
            }
        }

        window.onload = function(){
            //给删除选中按钮添加单击事件
            document.getElementById("delSelected").onclick = function(){
                if(confirm("您确定要删除选中条目吗？")){

                    var flag = false;
                    //判断是否有选中条目
                    var cbs = document.getElementsByName("uid");
                    for (var i = 0; i < cbs.length; i++) {
                        if(cbs[i].checked){
                            //有一个条目选中了
                            flag = true;
                            break;
                        }
                    }

                    if(flag){//有条目被选中
                        //表单提交
                        document.getElementById("form").submit();
                    }

                }

            }
            //1.获取第一个cb
            document.getElementById("firstCb").onclick = function(){
                //2.获取下边列表中所有的cb
                var cbs = document.getElementsByName("uid");
                //3.遍历
                for (var i = 0; i < cbs.length; i++) {
                    //4.设置这些cbs[i]的checked状态 = firstCb.checked
                    cbs[i].checked = this.checked;

                }

            }
        }


    </script>
</head>
<body>
<div class="container">
    <h3 style="text-align: center">菜品信息列表</h3>



    <div style="float :right;margin:5px">
            <c:if test="${sessionScope.user.userType==1}">
                <a class="btn btn-primary" href="adminlogin.jsp">管理员页面</a></td>
            </c:if>
            <c:if test="${sessionScope.user.userType==2}">
                <a class="btn btn-primary" href="salelogin.jsp">商家主页面</a></td>
            </c:if>
            <c:if test="${sessionScope.user.userType==3}">
                <a class="btn btn-primary" href="ctmlogin.jsp">客户主页面</a></td>
            </c:if>

            <a class="btn btn-primary" href="tourists.jsp">转到游客界面</a></td>



            <a class="btn btn-primary" href="javascript:history.go(-1)">返回上一页</a></td>
            <c:if test="${sessionScope.user.userType==1 || sessionScope.user.userType==2}">
                <a class="btn btn-primary" href="${pageContext.request.contextPath}/adddish.jsp">添加菜品</a></td>
            </c:if>
            <c:if test="${sessionScope.user.userType==1 || sessionScope.user.userType==2 ||sessionScope.user.userType==3}">
                <!--充钱-->
                <a class="btn btn-primary" href="${pageContext.request.contextPath}/addmoney.jsp">充值系统</a></td>
            </c:if>

    </div>
    <table border="1" class="table table-bordered table-hover">
        <tr class="success">
            <th>编号</th>
            <th>菜品名</th>
            <th>单价</th>
            <th>数量</th>
            <th>销量</th>
            <th>发布时间</th>
            <th>操作</th>
        </tr>

        <c:forEach items="${dishs}" var="dish" varStatus="s">
            <tr>

                <td>${s.count}</td>
                <td>${dish.dame}</td>
                <td>${dish.dPrice}</td>
                <td>${dish.dNum}</td>
                <td>${dish.dSum}</td>
                <td>${dish.dTime}</td>

                <!--游客不能下单-->
                <c:if test="${sessionScope.user.userType!=4}">
<%--                    发送数据捏--%>
                    <td>
                    <c:if test="${sessionScope.user.userType==1||sessionScope.user.userType==2||sessionScope.user.userType==3}">
                        <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/ctmServlet?function=func3&did=${dish.dId}&uid=${sessionScope.user.uId}">去下单</a>&nbsp;
                    </c:if>
                    <c:if test="${sessionScope.user.userType==3}">
                        <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/ctmServlet?function=func4&did=${dish.dId}&uid=${sessionScope.user.uId}">去评价</a>&nbsp;
                    </c:if>

                    <c:if test="${sessionScope.user.userType==1||sessionScope.user.userType==2}">
                        <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/deleteDishServlet?did=${dish.dId}">删除菜品</a>&nbsp;
                    </c:if>
                    </td>
                </c:if>

            </tr>
        </c:forEach>


    </table>
    <div>
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <li>
                    <a href="#" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
                <li><a href="#">1</a></li>
                <li><a href="#">2</a></li>
                <li><a href="#">3</a></li>
                <li><a href="#">4</a></li>
                <li><a href="#">5</a></li>
                <li>
                    <a href="#" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
                <span style="font-size: 20px;  margin-left:10px">
                    共16条，共四页
                </span>
            </ul>
        </nav>
    </div>
</div>
</body>
</html>
